import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TBargainShop } from "../../../Message/Db/Tables/TBargainShop";
import { SBargainShopPlayerItemInfo } from "../../../Message/Public/SBargainShopPlayerItemInfo";
type int = number;
//class BargainShopConfig
    
    export  class BargainShopConfig
    {
        constructor()
        {
            
            if (BargainShopConfig._instance) 
            {
                throw new Error("singleton instance!");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_bargain_shop.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this.levelKeys = [];
            var loc4=0;
            var loc5=arg1;
            for(loc3 of loc5) 
            {
                loc1 = new TBargainShop();
                this.copyData(loc1, loc3);
                loc2 = loc1.minLevel + "_" + loc1.maxLevel;
                if (this._map[loc2] == null) 
                {
                    this._map[loc2] = new Map<any, any> /* flash.utils.Dictionary */();
                    this.levelKeys.push(loc2);
                }
                this._map[loc2][loc1.code] = loc1;
            }
            return;
        }

        /* internal  */copyData(arg1: Object, arg2: Object): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg2;
            for (loc1 in loc3) 
            {
                if (!arg1.hasOwnProperty(loc1)) 
                {
                    continue;
                }
                arg1[loc1] = arg2[loc1];
            }
            return;
        }

        public getInfoByTypeCodeLevel(arg1: int, arg2: int): TBargainShop
        {
            var loc1=null;
            var loc3=0;
            var loc4=0;
            var loc5=null;
            var loc7=null;
            var loc2=this.levelKeys.length;
            var loc6=0;
            while (loc6 < loc2) 
            {
                loc1 = this.levelKeys[loc6];
                loc4 = (loc5 = loc1.split("_"))[0];
                loc3 = loc5[1];
                if (arg2 >= loc4 && arg2 <= loc3) 
                {
                    break;
                }
                ++loc6;
            }
            var loc8;
            return loc7 = (loc8 = this._map[loc1])[arg1] as TBargainShop;
        }

        public getCurListDataBySInfo(arg1: SBargainShopPlayerItemInfo): Array<any>
        {
            var loc2=null;
            var loc4=null;
            var loc5=null;
            var loc1=[];
            var loc3=arg1.itemInfo;
            var loc6=0;
            var loc7=loc3;
            for (loc5 in loc7) 
            {
                loc2 = this.getInfoByTypeCodeLevel(int(loc5), arg1.level);
                loc4 = {"info": loc2};
                loc1.push(loc4);
            }
            return loc1;
        }

        public static get instance(): BargainShopConfig
        {
            return BargainShopConfig._instance;
        }

        /* internal */ /* var */levelKeys: Array<any>;

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: BargainShopConfig;
    }

            BargainShopConfig._instance = new BargainShopConfig();
        